package pe.edu.upla.lamerced.bean;

// Generated 30/07/2010 10:51:09 PM by Hibernate Tools 3.2.4.GA

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;


/**
 * Users generated by hbm2java
 */
public class Users extends User implements java.io.Serializable {

	private String username;
	private String password;
	private Integer tipo;
	private String nombre;
	private String apePaterno;
	private String apeMaterno;
	private String nroDocumento;
	private Integer enabled;
	
	public Users() {		
		super("default", "default", true, true, true, true , uno() );
		System.out.println("constructor");
	}
	public static GrantedAuthority[] uno(){
		GrantedAuthority oo[] = { new GrantedAuthorityImpl("IS_AUTHENTICATED_ANONYMOUSLY") };
		return oo;
	}
        
	public Users(String username, String password, boolean enabled,GrantedAuthority[] authorities) {
		super(username, password, enabled, true, true, true, authorities);
		System.out.println("segundo costructor");
		this.enabled = enabled==true ? 1 : 0;
	}
	
	public Users(String username, String password, boolean enabled,GrantedAuthority[] authorities,
			String users, String clave, Integer tipo, String nombre,
			String apePaterno, String apeMaterno, String nroDocumento,
			Integer estado) {
		super(username, password, enabled, true, true, true, authorities);
		System.out.println("tercer cosntructor");
		this.username = username;
		this.password = password;
		this.tipo = tipo;
		this.nombre = nombre;
		this.apePaterno = apePaterno;
		this.apeMaterno = apeMaterno;
		this.nroDocumento = nroDocumento;
		this.enabled = enabled==true ? 1 : 0;
	}

	public static Users getUsuarioBean() {
		Users nu = (Users)(SecurityContextHolder.getContext().getAuthentication().getPrincipal());
		if(nu != null) {
			System.out.println("usuario encontrato para la session " + nu.toString());
			return nu;
		}
		else return null;
	}
	
	public String getUsername() {
		return this.username;
	}

	public void setUsername(String users) {
		this.username = users;
		System.out.println("seteo nombre");
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String clave) {
		this.password = clave;
	}

	/**
	 * Tipo 1 = Admin<br/>
	 * Tipo 2 = Cliente<br/>
	 * @return
	 */
	public Integer getTipo() {
		return this.tipo;
	}

	public void setTipo(Integer tipo) {
		this.tipo = tipo;
	}

	public String getNombre() {
		return this.nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public String getApePaterno() {
		return this.apePaterno;
	}

	public void setApePaterno(String apePaterno) {
		this.apePaterno = apePaterno;
	}

	public String getApeMaterno() {
		return this.apeMaterno;
	}

	public void setApeMaterno(String apeMaterno) {
		this.apeMaterno = apeMaterno;
	}

	public String getNroDocumento() {
		return this.nroDocumento;
	}

	public void setNroDocumento(String nroDocumento) {
		this.nroDocumento = nroDocumento;
	}

	public Integer getEnabled() {
		return this.enabled;
	}

	public void setEnabled(Integer estado) {
		this.enabled = estado;
	}

	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this,ToStringStyle.MULTI_LINE_STYLE);
	}
        
	public String getNombrecompleto(){
		return nombre +" "+ apePaterno + " "+ apeMaterno;
	}
}
